<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<%@ page import = "java.util.ArrayList" %>
<%@ page import = "quiz.Question" %>
<%@ page import = "quiz.Answer" %>
<%
	boolean isInline = false;
	if (request.getAttribute("isInline") != null) isInline = Boolean.parseBoolean((String)request.getAttribute("isInline"));
	Question q = (Question)request.getAttribute("currentQuestion");
	ArrayList<Answer> answers = q.getAnswers();
		
	if (isInline) out.println("<div id = \"question\" class = \"bottom_border\">");
	else out.println("<div id = \"question\">");
	
	int questionNum = (Integer)request.getAttribute("questionNumber");
	
	String question = q.getContent();
	String responseStructure = "";
	String name = "answer" + q.getID();
	
	switch(q.getType()) {
	case Question.FITB:
		int blankIndex = question.indexOf("_");
		if (request.getAttribute("shouldAllowAnswer") != null && (Boolean)request.getAttribute("shouldAllowAnswer")) question = question.substring(0, blankIndex)+" <input type = \"text\" class = \"response\" name = \""+name+"\" /> "+question.substring(blankIndex + 1);
		break;
	case Question.MC:
		for(Answer a: answers) {
			responseStructure += "<p><input type = \"radio\" name = \""+name+"\" value = \""+a.getContent()+"\"> "+a.getContent()+"</p>";
		}
		break;
	case Question.QR:
		responseStructure += "Response: <input type = \"text\" class = \"response\" name = \""+name+"\"></textarea>";
		break;
	case Question.PICTURE:
		question = "<img class = \"question_image\" src = \""+question+"\" />";
		responseStructure += "Response: <input type = \"text\" class = \"response\" name = \""+name+"\"></textarea>";
	}
	
	question = "<p>"+question+"</p>";
		
	
	out.println("<div id = \"section_title\"");
	if (!isInline) out.println(" class = \"bottom_border\"");
	out.println("><p><b>Question "+questionNum+":</b></p>"+question+"</div>");

	//TODO add timer (possibly)
	if (request.getAttribute("shouldAllowAnswer") != null && (Boolean)request.getAttribute("shouldAllowAnswer")) {
		out.println("<div class = \"answer\">"+responseStructure+"</div>");
	}
%>
</div>